package com.cloud.bssp.thread.sync;

/**
 * @description： 方法上的锁
 * @author：weirx
 * @date：2021/11/25 13:39
 * @version：3.0
 */
public class MethodSynchronized {

    public synchronized void test1() {
        System.out.println("this is test1");
    }

    public void test2() {
        synchronized (this) {
            System.out.println("this is test2");
        }
    }

    public static synchronized void test3() {
        System.out.println("this is test3");
    }

    public void test4() {
        synchronized (MethodSynchronized.class) {
            System.out.println("this is test4");
        }
    }

    public static void main(String[] args) {
        MethodSynchronized methodSynchronized = new MethodSynchronized();
        methodSynchronized.test1();
        methodSynchronized.test2();
    }
}
